package com.xq.demo;

import cn.hutool.crypto.SecureUtil;
import com.google.common.collect.Lists;
import com.sun.prism.shader.Solid_TextureYV12_AlphaTest_Loader;
import org.apache.commons.lang3.StringUtils;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ThreadDemo {

    public static void main(String[] args) throws Exception{


       // CreateTread t1 = new CreateTread();
        //t1.start();
       /* CreateRunable createRunable = new CreateRunable();
        Thread t2 = new Thread(createRunable);
        t2.start();

        Thread t3 = new Thread(createRunable);
        t3.start();*/

        /*ThreadVolatileDemo threadVolatileDemo = new ThreadVolatileDemo();
        Thread t = new Thread(threadVolatileDemo);
        t.start();
        Thread.sleep(3000);
        threadVolatileDemo.setRuning(false);
        System.out.println("flag 已经设置成false");

        int b=2;
        int a=1;
         a=b+1;*/
        /*String str = "6ce73ffd-b97c-415b-9408-5a8326d7b81b"+"|"+"aea43111aa87807fb79939b28256b929";
        String s = SecureUtil.md5(str);*/
        //System.out.println(s);
       List list = Lists.newArrayList();
       Long time = System.currentTimeMillis();
        System.out.println(time);
        list.add("6ce73ffd-b97c-415b-9408-5a8326d7b81b");
        list.add(String.valueOf(time));
        list.add("aea43111aa87807fb79939b28256b929");
        String str = StringUtils.join(list,"|");
        System.out.println(SecureUtil.md5(str));
        //System.out.println(System.currentTimeMillis());

    }


static class ThreadVolatileDemo implements Runnable{
    public volatile boolean  flag = true;

    @Override
    public void run() {
        System.out.println("开始执行子线程....");
        while (flag) {
        }
        System.out.println("线程停止");
    }
    public void setRuning(boolean flag) {
        this.flag = flag;
    }
}




    static class CreateTread extends Thread{
        @Override
        public void run() {
            for(int i=0;i<10;i++){
                System.out.println(Thread.currentThread().getName()+"i:" + i);
            }

        }
    }






    static class CreateRunable implements Runnable{

        public  AtomicInteger trainCount = new AtomicInteger(100);

        @Override
        public void run() {

            for(int i=0;i<100;i++){
                sale();

            }

        }

        public  void sale(){
                if(trainCount.get() >0){
                    System.out.println(Thread.currentThread().getName() + ",出售第" + (100 - trainCount.get()  + 1) + "张票");
                    trainCount.getAndIncrement();
                }


        }
    }


}


